<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>企业招聘者登录</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            background-color: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 6px 16px rgba(0,0,0,0.08);
            width: 400px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        button[type="submit"] {
            background-color: var(--primary);
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
        }
        button[type="submit"]:hover {
            background-color: var(--primary-dark);
        }
        .register-link {
            margin-top: 15px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>企业招聘者登录</h2>
        <form id="companyLoginForm">
            <div class="form-group">
                <label for="loginAccount">企业邮箱</label>
                <input type="email" id="loginAccount" required 
                       pattern="^[a-zA-Z][\w.-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
                       placeholder="请输入企业邮箱"
                       title="请输入有效的企业邮箱地址（字母开头，包含@和域名）"
                       style="width: 100%; padding: 8px; box-sizing: border-box;">
            </div>
            <div class="form-group">
                <label for="loginPassword">密码</label>
                <input type="password" id="loginPassword" required 
                       minlength="8"
                       placeholder="请输入密码（至少8位）"
                       title="密码长度至少8位">
            </div>
            <button type="submit">登录</button>
            <div class="register-link">
                还未注册？<a href="register.html?role=company">立即注册</a>
            </div>
        </form>
    </div>

    <script>
        document.getElementById('companyLoginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const form = e.target;
            if (!form.checkValidity()) {
                alert('请填写正确的表单信息');
                return;
            }
            
            const account = document.getElementById('loginAccount').value;
            const password = document.getElementById('loginPassword').value;
            
            // 从localStorage获取已注册用户信息（实际开发中应调用后端API）
            const registeredUsers = JSON.parse(localStorage.getItem('companyUsers') || '[]');
            const user = registeredUsers.find(u => u.email === account && u.password === password);
            
            if (user) {
                alert('登录成功，即将跳转到企业招聘页面');
                setTimeout(() => window.location.href = 'company-recruitment.html', 1500);
            } else {
                alert('账号或密码错误，或未注册');
                window.location.href = 'register.html?role=company';
            }
        });
    </script>
</body>
</html>